package com.cyl.wms.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyl.wms.domain.Area;
import com.cyl.wms.domain.Material;
import com.cyl.wms.mapper.MaterialMapper;
import com.cyl.wms.pojo.query.MaterialQuery;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
* @author zhipeng
* @description 针对表【erp_material(物料)】的数据库操作Service
* @createDate 2024-02-03 22:07:04
*/
@Service
public class MaterialService {
    @Autowired
    private MaterialMapper materialMapper;
    public List<Material> selectList(MaterialQuery query, Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<Material> qw = new QueryWrapper<>();
        qw.eq("del_flag",0);
//        String areaNo = query.getAreaNo();
//        if (!StringUtils.isEmpty(areaNo)) {
//            qw.eq("area_no", areaNo);
//        }
//        String areaNameLike = query.getAreaNameLike();
//        if (!StringUtils.isEmpty(areaNameLike)) {
//            qw.like("area_name", areaNameLike);
//        }
//        Long warehouseId = query.getWarehouseId();
//        if (warehouseId != null) {
//            qw.eq("warehouse_id", warehouseId);
//        }
        return materialMapper.selectList(qw);
    }

    /**
     * 获取全部数据
     * @param query 物料
     * @return 结果
     *
    * */
    public List<Material> selectListAll(MaterialQuery query) {
        QueryWrapper<Material> qw = new QueryWrapper<>();
        qw.eq("del_flag",0);
        Long materialId = query.getMaterialId();
        if (materialId != null) {
            qw.eq("material_id", materialId);
        }
        return materialMapper.selectList(qw);
    }

    /**
     * 新增物料
     *
     * @param material 物料
     * @return 结果
     */
    public int insert(Material material) {
//        material.setDelFlag(0);
//        material.setCreateTime(LocalDateTime.now());
        return materialMapper.insert(material);
    }

    /**
     * 批量删除货区
     *
     * @param ids 需要删除的货区主键
     * @return 结果
     */
    public int deleteByIds(Long[] ids) {
        return materialMapper.updateDelFlagByIds(ids);
    }
}
